package com.yzt.minemodule.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.yzt.zhuju.network.entity.mine.UserLevelBean;
import com.yzt.zhuju.network.entity.mine.UserLevelChildBean;
import com.yzt.zhuju.widget.DisableRecyclerView;
import com.yzt.zhuju.widget.tuiview.TUILinearLayout;
import com.yzt.zhuju.widget.tuiview.TUITextView;
import com.yzt.minemodule.R;

/**
 * author : bob
 * date   : 2023/1/16
 * desc   : 用户等级
 */
public class UserLevelAdapter extends BaseQuickAdapter<UserLevelBean, BaseViewHolder> {

    private int extraType;

    public void setType(int type) {
        this.extraType = type;
    }

    public UserLevelAdapter() {
        super(R.layout.item_user_level);
    }

    @Override
    protected void convert(BaseViewHolder holder, UserLevelBean item) {
        holder.setText(R.id.tv_title, item.getTitle());
        holder.setText(R.id.tv_content, item.getContent());
        TUITextView title = holder.findView(R.id.tv_title);
        TUITextView content = holder.findView(R.id.tv_content);
        title.setSelected(extraType == 1);
        content.setSelected(extraType == 1);

        DisableRecyclerView recyclerView = holder.findView(R.id.recycler_view);

        if (item.getList() == null || item.getList().isEmpty()) {
            recyclerView.setVisibility(View.GONE);
            holder.setVisible(R.id.tv_content, true);
        } else {
            recyclerView.setVisibility(View.VISIBLE);
            holder.setVisible(R.id.tv_content, false);
            UserLevelChildAdapter userLevelAdapter = new UserLevelChildAdapter();
            userLevelAdapter.setType(extraType);
            recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            recyclerView.setAdapter(userLevelAdapter);
            userLevelAdapter.addData(item.getList());
        }
    }

    public static class UserLevelChildAdapter extends BaseQuickAdapter<UserLevelChildBean, BaseViewHolder> {

        private int extraType;

        public void setType(int type) {
            this.extraType = type;
        }

        public UserLevelChildAdapter() {
            super(R.layout.item_user_level_child);
        }

        @Override
        protected void convert(BaseViewHolder holder, UserLevelChildBean item) {
            ImageView imgView = holder.findView(R.id.img_icon);
            Glide.with(getContext()).load(item.getPath()).into(imgView);

            holder.setText(R.id.tv_child_title, item.getTitle());
            holder.setText(R.id.tv_child_content, item.getContent());

            TUILinearLayout llContainer = holder.findView(R.id.ll_container);
            llContainer.setSelected(extraType == 1);
        }
    }
}
